# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=knob
pkgname=haskell-knob
pkgver=0.2.2
pkgrel=4
pkgdesc="Memory-backed handles"
url="https://github.com/ncfavier/knob"
license=("MIT")
arch=('loong64' 'x86_64')
depends=('ghc-libs')
makedepends=('ghc' 'haskell-chell')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('415772aae8fdedca8b23217fbc90006876eb924e6f5d01e63f2f4e2f3639b9c7a9331694f309c41fe378f2b498a0ce9cfac3b5d1d14744387501c2a84c0c1518')

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 "license.txt" "${pkgdir}/usr/share/licenses/${pkgname}/license.txt"
    rm -f "${pkgdir}/usr/share/doc/${pkgname}/license.txt"
}
